import { ajax } from '@/utils'

import type {
  ActivityItem,
  GetActivityBrandAreaRes,
  GetActivityImportRes,
  GetActivityListRes,
  GetActivityRestaurantRes,
  GetIndexLabelListRes,
  GetOrderDetailRes,
  GetOrderListRes,
  GetRestaurantListRes
} from './orderTypes'

const baseUrl = '/yswy-jdzq-back-service'

export default {
  /** 门店列表 */
  getRestaurantList(data): Promise<GetRestaurantListRes> {
    return ajax.post(`${baseUrl}/restaurant/list`, data)
  },
  /** 订单列表 */
  getOrderList(data): Promise<GetOrderListRes> {
    return ajax.post(`${baseUrl}/v1/order/list`, data)
  },
  /** 退款列表 */
  getOrderRefund(data): Promise<GetOrderListRes> {
    return ajax.post(`${baseUrl}/v1/order/refund/list`, data)
  },
  /** 订单详情 */
  getOrderDetail(id): Promise<GetOrderDetailRes> {
    return ajax.get(`${baseUrl}/v1/order/detail?id=${id}`)
  },
  /** 部分退款 */
  partOrderRefund(orderNo, slogan, gold, price): Promise<any> {
    return ajax.post(`${baseUrl}/v1/order/partRefund/`, {
      orderNo,
      slogan,
      gold,
      price
    })
  },
  /** 退款 */
  orderRefund(outTradeNo) {
    return ajax.get(`${baseUrl}/v1/order/refund?outTradeNo=${outTradeNo}`)
  },
  /** 折扣列表 */
  getIndexLabel(): Promise<GetIndexLabelListRes> {
    return ajax.get(`${baseUrl}/indexLabel/list`)
  },
  /** 首页折扣标签编辑 */
  putIndexLabel(data) {
    return ajax.put(`${baseUrl}/indexLabel/edit`, data)
  },
  /** 限时活动列表 */
  getActivityList(data): Promise<GetActivityListRes> {
    return ajax.post(`${baseUrl}/activity/list`, data)
  },
  /** 活动状态更改 */
  activityChange(id: number) {
    return ajax.put(`${baseUrl}/activity/upOrDown/${id}`)
  },
  /** 新增限时活动 */
  activityAdd(data) {
    return ajax.post(`${baseUrl}/activity/add`, data)
  },

  /** 编辑活动 */
  activityEdit(data: ActivityItem) {
    return ajax.put(`${baseUrl}/activity/edit`, data)
  },
  /** 活动详情 */
  getActivityDetail(id): Promise<ActivityItem> {
    return ajax.get(`${baseUrl}/activity/detail/${id}`)
  },

  /** 导入excel */
  activityImport(data): Promise<GetActivityImportRes> {
    return ajax.get(`${baseUrl}/activity/import`, data)
  },
  /** 导出订单 */
  activityExport(id: number) {
    return ajax.get(`${baseUrl}/activity/export/${id}`, {
      responseType: 'blob',
      withResponse: true
    })
  },
  /** 供应商对应地区 */
  getActivityBrandArea(brandId: number): Promise<GetActivityBrandAreaRes> {
    return ajax.get(`${baseUrl}/activity/brandArea/${brandId}`)
  },
  /** 活动门店列表 */
  getActivityRestaurant(data): Promise<GetActivityRestaurantRes> {
    return ajax.get(
      `${baseUrl}/activity/restaurant?brandId=${data['brandId']}${
        data['province'] ? `&province=${data['province']}` : ''
      }${data['city'] ? `&city=${data['city']}` : ''}`
    )
  }
}
